<?php

class LilCurrentUser {
/**
 * initialize method
 *
 * Initialize
 *
 * @return void
 */
	public function initialize() {
		//$_this = self::getInstance();
	}
/**
 * Return a singleton instance of the LilPluginRegistry.
 *
 * @return LilPluginRegistry instance
 */
	public static function &getInstance() {
		static $instance = array();
		if (!$instance) {
			$instance[0] =& new LilCurrentUser();
		}
		return $instance[0];
	}
/**
 * user method
 *
 * Returns current user
 *
 * @param mixed $key
 * @return mixed
 */
	public function get($key = null) {
		if (CakeSession::check(Configure::read('Lil.authSessionKey'))) {
			if ($key == null) {
				return array(
					Configure::read('Lil.authModel') => 
						CakeSession::read(Configure::read('Lil.authSessionKey'))
				);
			} else {
				$user = CakeSession::read(Configure::read('Lil.authSessionKey'));
				if (isset($user[$key])) return $user[$key];
			}
		}
		return null;
	}
/**
 * role method
 *
 * Returns user's role or checks if user has specified role
 * If there is no role specified, current role is returned
 *
 * @param mixed $check
 * @return mixed
 */
	public function role($check = null) {
		$User = ClassRegistry::init('Lil.User');
		return $User->role($check);
	}
/**
 * email method
 *
 * Returns default users email
 *
 * @return mixed
 */
	public function email() {
		$User = ClassRegistry::init('Lil.User');
		return $User->email();
	}
/**
 * canAccessArea method
 *
 * @param mixed $user_id
 * @access public
 * @return boolean
 */
	function canAccessArea($area_id = null) {
		if ($user_id = $this->get('id')) {
			$User = ClassRegistry::init('Lil.User');
			return $User->canAccessArea($user_id, $area_id);
		} else return false;
	}
}